import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AdditionApp extends JFrame  {
    JButton btnAdd;
    JTextField jtfNumber1, jtfNumber2;
    JLabel jlbResult;

    public AdditionApp() {
        jtfNumber1 = new JTextField("3", 10);
        jtfNumber2 = new JTextField("4", 10);
        jlbResult = new JLabel("7");
        btnAdd = new JButton("Add");
        btnAdd.addActionListener(new MyListener());

        JPanel commandpanel = new JPanel();
        commandpanel.add(new JLabel("Enter number 1: "));
        commandpanel.add(jtfNumber1);
        commandpanel.add(new JLabel("Enter number 2: "));
        commandpanel.add(jtfNumber2);
        commandpanel.add(new JLabel("Result:"));
        commandpanel.add(jlbResult);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().add(commandpanel, BorderLayout.CENTER);
        getContentPane().add(btnAdd, BorderLayout.SOUTH);
        setSize(600, 150);
        setVisible(true);
    }
    //complete the inner class
    class MyListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent e) {
            int numberOne = Integer.parseInt(jtfNumber1.getText());
            int numberTwo = Integer.parseInt(jtfNumber2.getText());
            jlbResult.setText((numberOne + numberTwo) + "");
        }
    }

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {new AdditionApp();}
        });
    }

}

